package com.infore.airsupervise.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.infore.airsupervise.R;
import com.infore.airsupervise.bean.AQIRealDataE;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * AQI界面因子列表适配器
 * <p>
 * 作者: dingxinlin
 * 创建日期: 2017/7/31 11:01
 */

public class FactorListAdapter extends BaseAdapter {

    private List<AQIRealDataE.FactorListBean> datas;
    private LayoutInflater layoutInflater;

    public FactorListAdapter(Context context, List<AQIRealDataE.FactorListBean> datas) {
        this.datas = datas;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas==null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = layoutInflater.inflate(R.layout.item_factor_recycler_view, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        AQIRealDataE.FactorListBean data = datas.get(i);

        holder.name.setText(data.getName());
        holder.value.setText(data.getValue() + "");
        holder.unit.setText(data.getUnit());

        return view;
    }

    class ViewHolder {
        @BindView(R.id.factor_name)
        TextView name;
        @BindView(R.id.factor_value)
        TextView value;
        @BindView(R.id.factor_unit)
        TextView unit;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
